package com.mdp.workflow.ru.service;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mdp.core.entity.Result;
import com.mdp.core.err.BizException;
import com.mdp.core.service.BaseService;
import com.mdp.core.utils.BaseUtils;
import com.mdp.core.utils.ObjectTools;
import com.mdp.form.FormUtil;
import com.mdp.form.entity.FormDataVo;
import com.mdp.micro.client.CallBizService;
import com.mdp.safe.client.entity.User;
import com.mdp.safe.client.utils.LoginUtils;
import com.mdp.workflow.api.ExecutionService;
import com.mdp.workflow.pub.service.SysUserService;
import com.mdp.workflow.re.entity.ProcdefNodeInfo;
import com.mdp.workflow.re.service.ProcdefNodeInfoService;
import com.mdp.workflow.ru.entity.ProcinstParames;
import com.mdp.workflow.ru.entity.ProcinstTag;
import com.mdp.workflow.ru.entity.Task;
import com.mdp.workflow.ru.listener.PushImMsgService;
import com.mdp.workflow.ru.mapper.TaskMapper;
import com.mdp.workflow.ru.vo.RejectActivity;
import com.mdp.workflow.ru.vo.TaskCandidateVo;
import com.mdp.workflow.ru.vo.TaskCompleteVo;
import org.apache.commons.lang3.StringUtils;
import org.flowable.common.engine.api.FlowableException;
import org.flowable.common.engine.api.FlowableIllegalArgumentException;
import org.flowable.engine.IdentityService;
import org.flowable.engine.RuntimeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import java.util.stream.Collectors;

/**
 * 父类已经支持增删改查操作,因此,即使本类什么也不写,也已经可以满足一般的增删改查操作了.<br> 
 * 组织 com.mdp  顶级模块 workflow 大模块 ru 小模块 <br>
 * 实体 Task 表 act_ru_task 当前主键(包括多主键): id_; 
 ***/
@Service("mdp.workflow.ru.TaskServiceImpl")
public class TaskServiceImpl extends BaseService<TaskMapper,Task> {
	static Logger logger =LoggerFactory.getLogger(TaskServiceImpl.class);


	@Value(value = "${mdp.form.data-approva-uri:/lcode/formData/processApprova}")
	String formDataApprovaUri="";

	@Autowired
	org.flowable.engine.TaskService taskService;

	@Autowired
	RuntimeService runtimeService;

	@Autowired
	IdentityService identityService;

	@Autowired
	ExecutionService executionService;

	@Autowired
	public ProcinstParamesService procinstParamesService;

	@Autowired
	public ProcinstTagService procinstTagService;




	@Autowired
	ProcdefNodeInfoService procdefNodeInfoService;

	@Autowired
	CallBizService callBizService;


	@Autowired
	PushImMsgService pushMsgService;



	@Autowired
	SysUserService sysUserService;


	/**
	 * 自定义查询，支持多表关联
	 * @param page 分页条件
	 * @param ew 一定要，并且必须加@Param("ew")注解
	 * @param ext 如果xml中需要根据某些值进行特殊处理，可以通过这个进行传递，非必须，注解也可以不加
	 * @return
	 */
	public List<Map<String,Object>> selectListMapByWhere(IPage page, QueryWrapper ew, Map<String,Object> ext){
		List<Map<String, Object>> datas = baseMapper.selectListMapByWhere(page,ew,ext);

		if(datas==null||datas.size()==0) {
			return datas;
		}
		Set<String> set=new HashSet<>();
		for (Map<String, Object> data : datas) {
			set.add((String) data.get("assignee"));
		}
		Map<String,String> umap=sysUserService.selectUserMapForSimpleInfoByUserids(set.stream().collect(Collectors.toList()));
		if(umap==null || umap.size()==0){
			return datas;
		}
		for (Map<String, Object> data : datas) {
			String id= (String) data.get("assignee");
			data.put("assigneeName",umap.get(id));
		}
		return datas;
	}

	@Transactional
	public Result completeTask(TaskCompleteVo taskCompleteVo){
		try {

			User user= LoginUtils.getCurrentUserInfo();
			ProcinstParames procinstParames=taskCompleteVo.getProcinstParames();
			FormDataVo formData=taskCompleteVo.getFormData();
			Map<String,Object> vars=executionService.procInstVarsHandle(procinstParames, formData,null);
			Map<String,Object> localVars=executionService.localVarsHandle(procinstParames, formData,vars,taskCompleteVo.getLocalVars());

			if(formData!=null && "1".equals(procinstParames.getIsRefForm()) ){
				if(!StringUtils.isEmpty(procinstParames.getFormId())) {
					List<ProcdefNodeInfo> nodeInfoVos=this.procdefNodeInfoService.getProcdefNodeInfosFromCache(procinstParames.getProcDefId(),procinstParames.getBranchId());
					ProcdefNodeInfo nodeInfo=null;

					if(nodeInfoVos!=null) {
						String actId=taskCompleteVo.getActId();
						if(StringUtils.isEmpty(actId)) {
							return Result.error("actId不能为空");
							
						}
						for (ProcdefNodeInfo procdefNodeInfoVo : nodeInfoVos) {
							if(procdefNodeInfoVo.getActId().equals(actId)) {
								nodeInfo=procdefNodeInfoVo;
								break;
							}
						}
					}
					Map<String,Object> formDataMap= BaseUtils.toMap(formData);
					if(nodeInfo!=null && !StringUtils.isEmpty(nodeInfo.getFormFieldsJson() ) && nodeInfo.getFormFieldsJson().startsWith("{")) {

						JSONObject jsonObject=JSONObject.parseObject(nodeInfo.getFormFieldsJson());
						//只推送本节点能改的数据 
 						String edit=jsonObject.getString("edit");
						localVars.put(FormUtil.NEED_UPDATE_FORM_DATA_FIELD_ID_LIST, edit);
					}
					localVars.put("formId", procinstParames.getFormId());
					localVars.put("formData",formDataMap);
					if(StringUtils.isEmpty(procinstParames.getRestUrl())) {
						localVars.put("restUrl",formDataApprovaUri);
					}
				}
			}

			localVars.put("currentUserid", user.getUserid());
			localVars.put("currentUsername", user.getUsername());
			localVars.put("startUserid", procinstParames.getUserid());
			localVars.put("action", taskCompleteVo.getAction());
			String[] nextAssigneeList=taskCompleteVo.getNextAssigneeList();
			identityService.setAuthenticatedUserId(user.getUserid());
			identityService.setUserInfo(user.getUserid(), "username", user.getUsername());
			identityService.setUserInfo(user.getUserid(), "branchId", user.getBranchId());
			if("claim".equals(taskCompleteVo.getAction())){//候选人领取任务，该任务没有任何人领取过 也就是assignee必须为空
				if(nextAssigneeList==null || nextAssigneeList.length==0 || nextAssigneeList.length>1) {
					return Result.error("need-single-assignee", "nextAssigneeList", "领取人不能为空");
					
				}
				this.addCommentMsg(user.getUserid(), taskCompleteVo.getTaskId(), taskCompleteVo.getProcInstId(), taskCompleteVo.getCommentMsg());
				taskService.claim(taskCompleteVo.getTaskId(), nextAssigneeList[0]);//领取任务
				pushMsgService.pushTaskMsgToIm(nextAssigneeList[0], taskCompleteVo.getProcinstParames().getMainTitle(), "", taskCompleteVo.getCommentMsg(), "");
				//taskService.setAssignee(taskCompleteVo.getTaskId(),nextAssigneeList[0]);
			} else if("transfer".equals(taskCompleteVo.getAction())){//转办 转给别人办理 代办
				if(nextAssigneeList==null || nextAssigneeList.length==0 || nextAssigneeList.length>1) {
					return Result.error("need-single-assignee", "nextAssigneeList", "请选择任务执行人");
				}
				this.addCommentMsg(user.getUserid(), taskCompleteVo.getTaskId(), taskCompleteVo.getProcInstId(), taskCompleteVo.getCommentMsg());
				//taskService.claim(taskCompleteVo.getTaskId(), nextAssigneeList[0]);//指派当前任务给他人
				taskService.setAssignee(taskCompleteVo.getTaskId(),nextAssigneeList[0]);
				pushMsgService.pushTaskMsgToIm(nextAssigneeList[0], taskCompleteVo.getProcinstParames().getMainTitle(), "", taskCompleteVo.getCommentMsg(), "");
			}else if("agree".equals(taskCompleteVo.getAction())||"disAgree".equals(taskCompleteVo.getAction())){ //自己办理/同意或者不同意

				if("agree".equals(taskCompleteVo.getAction())) {
					vars.put("agree", "1");
				}else if("disAgree".equals(taskCompleteVo.getAction())){
					vars.put("agree", "0");
				}
				if("need-single-assignee".equals(taskCompleteVo.getTipscode())) {
					if(nextAssigneeList!=null && nextAssigneeList.length>0) {
						localVars.put("assignee", nextAssigneeList[0]);
					}else {
						throw new BizException("need-single-assignee", "请选择执行人");
					}
				}else if("need-mulit-assignee".equals(taskCompleteVo.getTipscode())) {
					if(nextAssigneeList!=null && nextAssigneeList.length>0) {

						List<String> assigneeList=new ArrayList<>();
						for (String assignee : nextAssigneeList) {
							assigneeList.add(assignee);
						}
						localVars.put("assigneeList", assigneeList);
					}else {
						throw new BizException("need-mulit-assignee", "请选择会签人员");
					}
				}
				try {
					if(formData!=null && ObjectTools.isNotEmpty(formData.getChangeLogs())){
						this.addCommentMsg(user.getUserid(),taskCompleteVo.getTaskId(),taskCompleteVo.getProcInstId(),formData.getChangeLogs());
					}
					this.addCommentMsg(user.getUserid(), taskCompleteVo.getTaskId(), taskCompleteVo.getProcInstId(), taskCompleteVo.getCommentMsg());
					localVars.put("commentMsg", taskCompleteVo.getCommentMsg());
					taskService.complete(taskCompleteVo.getTaskId(), vars,localVars);//完成任务跳转到下一节点
					//taskService.com
				} catch (BizException e) {
					throw e;
				}catch(FlowableIllegalArgumentException e) {
					log.error("",e);
					//org.flowable.common.engine.api.FlowableIllegalArgumentException: Variable 'assigneeList' was not found
					if("Variable 'assigneeList' was not found".equals(e.getMessage())) {
						throw new BizException("need-mulit-assignee", "请选择会签人员");
					}else {
						throw e;
					}
				}catch (FlowableException e) {
					//org.flowable.common.engine.api.FlowableIllegalArgumentException: Variable 'assigneeList':[Ljava.lang.String;@28613abf is not a Collection
					//org.flowable.common.engine.api.FlowableException: Unknown property used in expression: ${assigneeList}
					//need-mulit-assignee
					log.error("",e);
					if("Unknown property used in expression: ${assigneeList}".equals(e.getMessage())) {
						throw new BizException("need-mulit-assignee", "请选择会签人员");
					}else if("Unknown property used in expression: ${assignee}".equals(e.getMessage())){
						throw new BizException("need-single-assignee", "请选择执行人员");
					}else {
						throw e;
					}
				}catch (Exception e) {
					//org.flowable.common.engine.api.FlowableIllegalArgumentException: Variable 'assigneeList':[Ljava.lang.String;@28613abf is not a Collection
					//org.flowable.common.engine.api.FlowableException: Unknown property used in expression: ${assigneeList}
					//need-mulit-assignee
					log.error("",e);
					throw e;
				}
			}else if("resolve".equals(taskCompleteVo.getAction())){//委托办理后，对应的办理人提交任务，任务回到委托人手中
				this.addCommentMsg(user.getUserid(), taskCompleteVo.getTaskId(), taskCompleteVo.getProcInstId(), taskCompleteVo.getCommentMsg());
				taskService.resolveTask(taskCompleteVo.getTaskId(), vars);//返回给任务拥有者
			}else if("delegate".equals(taskCompleteVo.getAction())){//委托办理
				if(nextAssigneeList==null || nextAssigneeList.length==0 || nextAssigneeList.length>1) {
					return Result.error("need-single-assignee", "nextAssigneeList", "请选择任务执行人");
				}
				this.addCommentMsg(user.getUserid(), taskCompleteVo.getTaskId(), taskCompleteVo.getProcInstId(), taskCompleteVo.getCommentMsg());
				taskService.delegateTask(taskCompleteVo.getTaskId(), nextAssigneeList[0]);//让其代理我的任务	
				pushMsgService.pushTaskMsgToIm(nextAssigneeList[0], taskCompleteVo.getProcinstParames().getMainTitle(), "", taskCompleteVo.getCommentMsg(), "");
			}else if("sponsors".equals(taskCompleteVo.getAction())){//转办，转交给主办人
				String sponsors=procinstParames.getUserid();
				if(!StringUtils.isEmpty(procinstParames.getSponsors())) {
					String[] sponsorss=procinstParames.getSponsors().split(",");
					sponsors=sponsorss[0];
				}
				this.addCommentMsg(user.getUserid(), taskCompleteVo.getTaskId(), taskCompleteVo.getProcInstId(), taskCompleteVo.getCommentMsg());

				taskService.setAssignee(taskCompleteVo.getTaskId(), sponsors);
				pushMsgService.pushTaskMsgToIm(sponsors, taskCompleteVo.getProcinstParames().getMainTitle(), "", taskCompleteVo.getCommentMsg(), "");
			}else if("rejectToStartUser".equals(taskCompleteVo.getAction())){//转办 转给发起人
				this.addCommentMsg(user.getUserid(), taskCompleteVo.getTaskId(), taskCompleteVo.getProcInstId(), taskCompleteVo.getCommentMsg());

				taskService.setAssignee(taskCompleteVo.getTaskId(), procinstParames.getUserid());
				pushMsgService.pushTaskMsgToIm(procinstParames.getUserid(), taskCompleteVo.getProcinstParames().getMainTitle(), "", taskCompleteVo.getCommentMsg(), "");
			}else if("rejectToActivity".equals(taskCompleteVo.getAction())){//驳回到任意已执行的节点
				RejectActivity ra=taskCompleteVo.getRejectActivity();
				if(ra==null) {
					throw new BizException("请指定驳回节点");
				}
				List<String> needPushMsgUsers=new ArrayList<>();
				if("need-single-assignee".equals(taskCompleteVo.getTipscode())) {
					if(nextAssigneeList!=null && nextAssigneeList.length>0) {
						localVars.put("assignee", nextAssigneeList[0]);
					}else {
						throw new BizException("need-single-assignee", "请选择执行人");
					}
				}else if("need-mulit-assignee".equals(taskCompleteVo.getTipscode())) {
					if(nextAssigneeList!=null && nextAssigneeList.length>0) {

						List<String> assigneeList=new ArrayList<>();
						for (String assignee : nextAssigneeList) {
							assigneeList.add(assignee);
							needPushMsgUsers.add(assignee);
						}
						localVars.put("assigneeList", assigneeList);
					}else {
						throw new BizException("need-mulit-assignee", "请选择会签人员");
					}
				}else {
					if(nextAssigneeList!=null && nextAssigneeList.length==1) {
						localVars.put("assignee", nextAssigneeList[0]);
						needPushMsgUsers.add(nextAssigneeList[0]);
					}else if(nextAssigneeList!=null && nextAssigneeList.length>1) {
						List<String> assigneeList=new ArrayList<>();
						for (String assignee : nextAssigneeList) {
							assigneeList.add(assignee);
							needPushMsgUsers.add(assignee);
						}
						localVars.put("assigneeList",assigneeList);
					}

				}
				List<String> currentActivityIds=new ArrayList<>();
				String newActivityId=ra.getTaskDefKey();
				List<org.flowable.task.api.Task> tasks = taskService.createTaskQuery().processInstanceId( taskCompleteVo.getProcInstId()).list();
				for (org.flowable.task.api.Task task : tasks) {
					log.debug("task.id="+task.getId());
					log.debug("task.taskDefinitionKey="+task.getTaskDefinitionKey());
					log.debug("task.taskDefinitionId="+task.getTaskDefinitionId());
					log.debug("task.executionId="+task.getExecutionId());
					log.debug("task.name="+task.getName());
					currentActivityIds.add(task.getTaskDefinitionKey());
				}
				this.addCommentMsg(user.getUserid(), taskCompleteVo.getTaskId(), taskCompleteVo.getProcInstId(), taskCompleteVo.getCommentMsg());

				runtimeService.createChangeActivityStateBuilder().processInstanceId( taskCompleteVo.getProcInstId()).localVariables(newActivityId, localVars).moveActivityIdsToSingleActivityId(currentActivityIds, newActivityId).changeState();
				for (String userid : needPushMsgUsers) {
					pushMsgService.pushTaskMsgToIm(userid, taskCompleteVo.getProcinstParames().getMainTitle(), "", taskCompleteVo.getCommentMsg(), "");
				}

				//taskService.setAssignee(taskCompleteVo.getTaskId(), procinstParames.getUserid());
			}else if("over".equals(taskCompleteVo.getAction())) {//直接结束流程
				if( procinstParames.getUserid().equals(user.getUserid())) {
					executionService.delExecution(taskCompleteVo.getProcInstId(),taskCompleteVo.getCommentMsg(),localVars);
				}else {
					return Result.error("只有发起人有权提前结束流程");
					
				}
			}
			if(!"over".equals(taskCompleteVo.getAction())) {
				//不允许修改基本信息
				if("1".equals(taskCompleteVo.getChangeTags())) {//如果修改了标签，要更新标签库 
					String procInstId=procinstParames.getProcInstId();
					String procDefId=procinstParames.getProcDefId();
					String branchId=procinstParames.getBranchId();
					String userid=procinstParames.getUserid();
					String tagIds=procinstParames.getTagIds();
					String tagNames=procinstParames.getTagNames();
					if(!StringUtils.isEmpty(tagIds) && !StringUtils.isEmpty(tagNames) ) {
						String[] tagIdsArr=tagIds.split(",");
						String[] tagIdsNamesArr=tagNames.split(",");
						if(tagIdsArr.length==tagIdsNamesArr.length) {
							List<ProcinstTag> tags=new ArrayList<>();
							for (String tagId : tagIdsArr) {
								ProcinstTag procinstTag =new ProcinstTag();
								procinstTag.setAddUserid(userid);
								procinstTag.setProcDefId(procDefId);
								procinstTag.setBranchId(branchId);
								procinstTag.setAddUserid(userid);
								procinstTag.setProcInstId(procInstId);
								procinstTag.setTagId(tagId);
								procinstTag.setId(this.createKey("id"));
							}
							this.procinstParamesService.updateTagsByProDefIdAndProcInstId(branchId, procDefId, procInstId, tagIds, tagNames);
							this.procinstTagService.batchInsertOrDeleteTags(branchId, procDefId, procInstId, userid, tags);
						}

					}
				}
			}
			
		} finally {
			identityService.setAuthenticatedUserId(null);

		}
		return Result.ok();
	}



	public void addCommentMsg(String userid,String taskId,String procInstId,String commentMsg) {
		if(!StringUtils.isEmpty(commentMsg)){
			try {
				taskService.addComment(taskId, procInstId, commentMsg);
			} finally {
			}
		}
	}





	public Result delCandidate(TaskCandidateVo candidateVo) {

		String[] userids=ObjectTools.isEmpty(candidateVo.getHxUserids())?null:candidateVo.getHxUserids().split(",");
		String[] deptids=ObjectTools.isEmpty(candidateVo.getHxDeptids())?null:candidateVo.getHxDeptids().split(",");
		String[] postids=ObjectTools.isEmpty(candidateVo.getHxPostids())?null:candidateVo.getHxPostids().split(",");
		String[] roleids=ObjectTools.isEmpty(candidateVo.getHxRoleids())?null:candidateVo.getHxRoleids().split(",");
		String taskId=candidateVo.getTaskId();
		String branchId=candidateVo.getBranchId();
		if(taskId==null || "".equals(taskId)) {
			return Result.error("taskId不能为空");
			
		}
		if(userids!=null && userids.length>0) {
			for (String userid : userids) {
				taskService.deleteCandidateUser(taskId, userid);
			}
		}

		if(deptids!=null && deptids.length>0) {
			for (String deptid : deptids) {
				if(!deptid.startsWith("_dept_")) {
					deptid="_dept_"+deptid;
				}
				taskService.deleteCandidateGroup(taskId, deptid);
			}
		}

		if(postids!=null && postids.length>0) {
			for (String postid : postids) {
				if(!postid.startsWith("_post_")) {
					postid="_post_"+postid;
				}
				taskService.deleteCandidateGroup(taskId, postid);
			}
		}
		if(roleids!=null && roleids.length>0) {
			for (String roleid : roleids) {
				if(!roleid.startsWith("_role_")) {
					roleid="_role_"+roleid;
				}
				taskService.deleteCandidateGroup(taskId, roleid);
			}
		}
		return Result.ok();
	}



	public Result addCandidate(TaskCandidateVo candidateVo) {

		String[] userids=ObjectTools.isEmpty(candidateVo.getHxUserids())?null:candidateVo.getHxUserids().split(",");
		String[] deptids=ObjectTools.isEmpty(candidateVo.getHxDeptids())?null:candidateVo.getHxDeptids().split(",");
		String[] postids=ObjectTools.isEmpty(candidateVo.getHxPostids())?null:candidateVo.getHxPostids().split(",");
		String[] roleids=ObjectTools.isEmpty(candidateVo.getHxRoleids())?null:candidateVo.getHxRoleids().split(",");

		List<Map<String,Object>> dbList=listCandidates(map("taskId",candidateVo.getTaskId()));

		String taskId=candidateVo.getTaskId();
		String branchId=candidateVo.getBranchId();
		if(taskId==null || "".equals(taskId)) {
			return Result.error("taskId不能为空");
			
		}
		if(branchId==null || "".equals(branchId)) {
			return Result.error("branchId不能为空");
			
		}

		Set<String> useridDbSet=dbList.stream().map(k->(String)k.get("userId")).filter(k->ObjectTools.isNotEmpty(k)).collect(Collectors.toSet());
		Set<String> roleidDbSet=dbList.stream().map(k->(String)k.get("groupId")).filter(k->ObjectTools.isNotEmpty(k) && k.startsWith("_role_")).collect(Collectors.toSet());
		Set<String> postidDbSet=dbList.stream().map(k->(String)k.get("groupId")).filter(k->ObjectTools.isNotEmpty(k) && k.startsWith("_post_")).collect(Collectors.toSet());
		Set<String> deptidDbSet=dbList.stream().map(k->(String)k.get("groupId")).filter(k->ObjectTools.isNotEmpty(k) && k.startsWith("_dept_")).collect(Collectors.toSet());

		if(userids!=null && userids.length>0) {
			for (String userid : userids) {
				if(!useridDbSet.contains(userid)){
					taskService.addCandidateUser(taskId, userid);
				}
			}
			for (String s : useridDbSet) {
				if(!Arrays.stream(userids).filter(k->s.equals(k)).findAny().isPresent()){
					taskService.deleteCandidateUser(taskId,s);
				}
			}
		}

		if(deptids!=null && deptids.length>0) {
			for (String deptid : deptids) {
				if(!deptid.startsWith("_dept_")) {
					deptid="_dept_"+deptid;
				}
				if(!deptidDbSet.contains(deptid)){
					taskService.addCandidateGroup(taskId, deptid);
				}

			}

			for (String s : deptidDbSet) {
				if(!Arrays.stream(deptids).filter(k->s.equals(k)).findAny().isPresent()){
					taskService.deleteCandidateGroup(taskId,s);
				}
			}
		}

		if(postids!=null && postids.length>0) {
			for (String postid : postids) {
				if(!postid.startsWith("_post_")) {
					postid="_post_"+postid;
				}
				if(!postidDbSet.contains(postid)){
					taskService.addCandidateGroup(taskId, postid);
				}

			}

			for (String s : postidDbSet) {
				if(!Arrays.stream(postids).filter(k->s.equals(k)).findAny().isPresent()){
					taskService.deleteCandidateGroup(taskId,s);
				}
			}
		}
		if(roleids!=null && roleids.length>0) {
			for (String roleid : roleids) {
				if(!roleid.startsWith("_post_")) {
					roleid="_role_"+roleid;
				}
				if(!roleidDbSet.contains(roleid)){
					taskService.addCandidateGroup(taskId, roleid);
				}

			}

			for (String s : roleidDbSet) {
				if(!Arrays.stream(roleids).filter(k->s.equals(k)).findAny().isPresent()){
					taskService.deleteCandidateGroup(taskId,s);
				}
			}
		}
		return Result.ok();
	}


	public List<Map<String, Object>> listCandidates(Map<String, Object> task) {
		List<Map<String,Object>> datas= baseMapper.listCandidates(task);
		return datas;
	}
}

